package ch.il07.converter.presentation;

import javax.faces.context.FacesContext;

public class AccessControl {
	private final static String[] PUBLIC_SITES = { 
			"/snippets/template.xhtml", 
			"/snippets/menu.xhtml",
			"/css/style.css",
			"/css/default.css",
			"/css/background.png",
			"/js/action.js", 
			
			
			"/index.xhtml", 
			"/welcome.xhtml", 
			"/aboutus.xhtml", 
			"/help.xhtml",
			"/info.xhtml",
			"/login.xhtml",
			"/start.xhtml",
			"/register.xhtml"
		};
	
	/**
	 * Checks if the file public accessible is.
	 * @return true if the file is whitelisted.
	 */
	public static boolean isPublicAccessibleFile() {
		FacesContext fc = Helper.getFacesContext();
		String viewId = fc.getViewRoot().getViewId();

		boolean accessGranted = false;
		for(String whiteListed : PUBLIC_SITES) {
			if(viewId.equals(whiteListed)) {
				accessGranted = true;
				break;
			}
		}
		return accessGranted;
	}
}